package com.dwxt.community.controller;

import com.dwxt.common.base.*;
import com.dwxt.community.entity.*;
import com.dwxt.community.service.*;
import org.apache.commons.lang.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;
/**
 *  评论 后台管理
 * @author shenwenkang
 */
@RestController
@RequestMapping("/cms/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 评论列表
     */
    @GetMapping("/get")
    public BaseResult get(@RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = "10")Integer pageSize) {
        return commentService.get(pageNum, pageSize);
    }
    /**
     * 根据用户ID获取评论
     */
    @GetMapping("/getByUserId")
    public BaseResult getByUserId(@RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10")Integer pageSize,
                                  String userId) {
        return commentService.getByUserId(pageNum,pageSize,userId);
    }
    /**
     * 根据资讯ID获取评论
     */
    @GetMapping("/getByInformationId")
    public BaseResult getByInformationId(@RequestParam(defaultValue = "1") Integer pageNum,
                                         @RequestParam(defaultValue = "10")Integer pageSize,
                                         String informationId) {
        return commentService.getByInformationId(pageNum,pageSize,informationId);
    }
    /**
     * 搜索评论
     */
    @GetMapping("/search")
    public BaseResult search(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10")Integer pageSize,
                             String content, String username) {
        return commentService.search(pageNum,pageSize,content,username);
    }

    /**
     * 添加评论
     *
     * @return
     */
    @PostMapping("/insert")
    public BaseResult get(Comment comment) {
        return commentService.insert(comment);
    }

    /**
     * 删除评论
     *
     * @param id
     * @return
     */
    @DeleteMapping("/del")
    public BaseResult del(String id) {
        if (StringUtils.isBlank(id)) {
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return commentService.del(id);
    }

    /**
     * 修改评论
     */
    @PostMapping("/update")
    public BaseResult update(Comment comment) {
        String id = comment.getId();
        if (StringUtils.isBlank(id)) {
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return commentService.update(comment);
    }
}
